﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZX.HIS.IDAL;
using ZX.HIS.DBUtility;
using System.Collections.Generic;
using System.Collections;//Please add references
namespace ZX.HIS.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:SeeDoctorMedicalItem
    /// </summary>
    public partial class SeeDoctorMedicalItem : ISeeDoctorMedicalItem
    {
        public SeeDoctorMedicalItem()
        { }

        #region SeeDoctorMedicalItem自写方法
        /// <summary>
        /// 事务处理检查医疗项和就诊表派生表添加
        /// </summary>
        /// <param name="SDMIList">检查医疗项集合</param>
        /// <param name="SeeDoctorId">就诊ID</param>
        /// <param name="HospitalId">诊所ID</param>
        /// <returns></returns>
        public bool SeeDoctorMedicalItemAdd(List<ZX.HIS.Model.SeeDoctorMedicalItem> SDMIList, int SeeDoctorId, int HospitalId)
        {
            if (SeeDoctorId == 0)
            {
                return false;
            }
            List<string> cmdTextList = new List<string>();
            List<List<SqlParameter>> cmdParametersList = new List<List<SqlParameter>>();

            //子表添加数据
            //Author: JiXiang 20120419
            //Modify Begin
            StringBuilder strSqlSub = new StringBuilder();
            strSqlSub.AppendLine("INSERT INTO tbSeeDoctorMedicalItem(");
            strSqlSub.AppendLine(" HospitalId,SeeDocMedicName,SeeDocMedicSalePrice,SeeDocMedicNumber,");
            strSqlSub.AppendLine("SeeDocMedicSumPrice,SeeDocMedicIsPay,SeeDoctorId)");
            strSqlSub.AppendLine(" VALUES (@HospitalId,@SeeDocMedicName,@SeeDocMedicSalePrice,@SeeDocMedicNumber,");
            strSqlSub.AppendLine(" @SeeDocMedicSumPrice,@SeeDocMedicIsPay,@SeeDoctorId)");
            //非空判定
            //Author: ZhaoLiang 22012-04-25
            if (SDMIList != null)
            {
                foreach (ZX.HIS.Model.SeeDoctorMedicalItem m in SDMIList)
                {
                    m.SeeDoctorId = SeeDoctorId;
                    m.HospitalId = HospitalId;
                    SqlParameter[] parametersSub = {
                           new SqlParameter("@HospitalId", SqlDbType.Int,8){Value = m.HospitalId},
                           new SqlParameter("@SeeDocMedicName", SqlDbType.VarChar,50){Value = m.SeeDocMedicName},
                           new SqlParameter("@SeeDocMedicSalePrice", SqlDbType.Decimal,9){Value = m.SeeDocMedicSalePrice},
                           new SqlParameter("@SeeDocMedicNumber", SqlDbType.Int,8){Value = m.SeeDocMedicNumber},
                           new SqlParameter("@SeeDocMedicSumPrice", SqlDbType.Decimal,9){Value = m.SeeDocMedicSumPrice},
                           new SqlParameter("@SeeDocMedicIsPay", SqlDbType.Int,8){Value = m.SeeDocMedicIsPay},
                           new SqlParameter("@SeeDoctorId", SqlDbType.Int,8){Value = m.SeeDoctorId}};
                    //Modify End
                    cmdTextList.Add(strSqlSub.ToString());
                    List<SqlParameter> SqlList = new List<SqlParameter>(parametersSub);
                    cmdParametersList.Add(SqlList);
                }
            }
            List<int> Result = SqlDBhelper.ExecuteNonQueryTran(cmdTextList, cmdParametersList);
            if (Result != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 修改检查医疗项和就诊表派生表
        /// </summary>
        /// <param name="SDMIList">数据</param>
        /// <returns></returns>
        public bool SeeDoctorMedicalItemUpt(List<ZX.HIS.Model.SeeDoctorMedicalItem> SDMIList)
        {
            List<string> cmdTextList = new List<string>();
            List<List<SqlParameter>> cmdParametersList = new List<List<SqlParameter>>();

            //子表修改数据
            //Author: JiXiang 20120419
            //Modify Begin
            StringBuilder strSqlSub = new StringBuilder();
            strSqlSub.AppendLine("UPDATE  tbSeeDoctorMedicalItem(");
            strSqlSub.AppendLine("SeeDocMedicName=@SeeDocMedicName,");
            strSqlSub.AppendLine("SeeDocMedicSalePrice=@SeeDocMedicSalePrice,");
            strSqlSub.AppendLine("SeeDocMedicNumber=@SeeDocMedicNumber,");
            strSqlSub.AppendLine("SeeDocMedicSumPrice=@SeeDocMedicSumPrice");
            strSqlSub.AppendLine(" WHERE SeeDocMedicId=@SeeDocMedicId");
            //非空判定
            //Author: ZhaoLiang 22012-04-25
            if (SDMIList != null)
            {
                foreach (ZX.HIS.Model.SeeDoctorMedicalItem m in SDMIList)
                {
                    SqlParameter[] parametersSub = {
                           new SqlParameter("@SeeDocMedicName", SqlDbType.VarChar,50){Value = m.SeeDocMedicName},
                           new SqlParameter("@SeeDocMedicSalePrice", SqlDbType.Decimal,9){Value = m.SeeDocMedicSalePrice},
                           new SqlParameter("@SeeDocMedicNumber", SqlDbType.Int,8){Value = m.SeeDocMedicNumber},
                           new SqlParameter("@SeeDocMedicSumPrice", SqlDbType.Decimal,9){Value = m.SeeDocMedicSumPrice},
                           new SqlParameter("@SeeDocMedicId", SqlDbType.Int,8){Value = m.SeeDocMedicId}};
                    //Modify End
                    cmdTextList.Add(strSqlSub.ToString());
                    List<SqlParameter> SqlList = new List<SqlParameter>(parametersSub);
                    cmdParametersList.Add(SqlList);
                }
            }
            List<int> Result = SqlDBhelper.ExecuteNonQueryTran(cmdTextList, cmdParametersList);
            if (Result != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        ///查询检查医疗项和就诊表派生表
        /// </summary>
        /// <param name="DAModel"></param>
        /// <returns></returns>
        public List<ZX.HIS.Model.SeeDoctorMedicalItem> SeeDoctorMedicalItemList(int SeeDoctorId)
        {
            string ComText = "Proc_SeeDoctorMedicalItemList";
            SqlParameter[] parameters = {
                     new SqlParameter("@SeeDoctorId", SqlDbType.Int,8){Value=SeeDoctorId}
                                        };
            List<ZX.HIS.Model.SeeDoctorMedicalItem> SDMIList = new List<Model.SeeDoctorMedicalItem>();
            DataSet ds = SqlDBhelper.RunProcedure(ComText, parameters, "db");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ZX.HIS.Model.SeeDoctorMedicalItem SDMIModel = DataRowToModel(ds.Tables[0].Rows[i]);
                    SDMIList.Add(SDMIModel);
                }
                return SDMIList;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZX.HIS.Model.SeeDoctorMedicalItem DataRowToModel(DataRow row)
        {
            ZX.HIS.Model.SeeDoctorMedicalItem model = new ZX.HIS.Model.SeeDoctorMedicalItem();
            if (row != null)
            {
                if (row["SeeDocMedicId"] != null && row["SeeDocMedicId"].ToString() != "")
                {
                    model.SeeDocMedicId = int.Parse(row["SeeDocMedicId"].ToString());
                }
                if (row["HospitalId"] != null && row["HospitalId"].ToString() != "")
                {
                    model.HospitalId = int.Parse(row["HospitalId"].ToString());
                }
                if (row["SeeDocMedicName"] != null)
                {
                    model.SeeDocMedicName = row["SeeDocMedicName"].ToString();
                }
                if (row["SeeDocMedicSalePrice"] != null && row["SeeDocMedicSalePrice"].ToString() != "")
                {
                    model.SeeDocMedicSalePrice = decimal.Parse(row["SeeDocMedicSalePrice"].ToString());
                }
                if (row["SeeDocMedicNumber"] != null && row["SeeDocMedicNumber"].ToString() != "")
                {
                    model.SeeDocMedicNumber = int.Parse(row["SeeDocMedicNumber"].ToString());
                }
                if (row["SeeDocMedicSumPrice"] != null && row["SeeDocMedicSumPrice"].ToString() != "")
                {
                    model.SeeDocMedicSumPrice = decimal.Parse(row["SeeDocMedicSumPrice"].ToString());
                }
                if (row["SeeDocMedicIsPay"] != null && row["SeeDocMedicIsPay"].ToString() != "")
                {
                    model.SeeDocMedicIsPay = int.Parse(row["SeeDocMedicIsPay"].ToString());
                }
                if (row["SeeDoctorId"] != null && row["SeeDoctorId"].ToString() != "")
                {
                    model.SeeDoctorId = int.Parse(row["SeeDoctorId"].ToString());
                }
            }
            return model;
        }
        #endregion
        #region  BasicMethod

        ///// <summary>
        ///// 得到最大ID
        ///// </summary>
        //public int GetMaxId()
        //{
        //return DbHelperSQL.GetMaxID("SeeDocMedicId", "tbSeeDoctorMedicalItem"); 
        //}

        ///// <summary>
        ///// 是否存在该记录
        ///// </summary>
        //public bool Exists(int SeeDocMedicId)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("select count(1) from tbSeeDoctorMedicalItem");
        //    strSql.AppendLine(" where SeeDocMedicId=@SeeDocMedicId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@SeeDocMedicId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = SeeDocMedicId;

        //    return DbHelperSQL.Exists(strSql.ToString(),parameters);
        //}


        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public int Add(ZX.HIS.Model.SeeDoctorMedicalItem model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("insert into tbSeeDoctorMedicalItem(");
        //    strSql.AppendLine(")");
        //    strSql.AppendLine(" values (");
        //    strSql.AppendLine("");
        //    strSql.AppendLine(";select @@IDENTITY");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDocMedicName", SqlDbType.VarChar,50),
        //            new SqlParameter("@SeeDocMedicSalePrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SeeDocMedicNumber", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDocMedicSumPrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SeeDocMedicIsPay", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDoctorId", SqlDbType.Int,4)};
        //    parameters[0].Value = model.HospitalId;
        //    parameters[1].Value = model.SeeDocMedicName;
        //    parameters[2].Value = model.SeeDocMedicSalePrice;
        //    parameters[3].Value = model.SeeDocMedicNumber;
        //    parameters[4].Value = model.SeeDocMedicSumPrice;
        //    parameters[5].Value = model.SeeDocMedicIsPay;
        //    parameters[6].Value = model.SeeDoctorId;

        //    object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(ZX.HIS.Model.SeeDoctorMedicalItem model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("update tbSeeDoctorMedicalItem set ");
        //    strSql.AppendLine("HospitalId=@HospitalId,");
        //    strSql.AppendLine("SeeDocMedicName=@SeeDocMedicName,");
        //    strSql.AppendLine("SeeDocMedicSalePrice=@SeeDocMedicSalePrice,");
        //    strSql.AppendLine("SeeDocMedicNumber=@SeeDocMedicNumber,");
        //    strSql.AppendLine("SeeDocMedicSumPrice=@SeeDocMedicSumPrice,");
        //    strSql.AppendLine("SeeDocMedicIsPay=@SeeDocMedicIsPay,");
        //    strSql.AppendLine("SeeDoctorId=@SeeDoctorId");
        //    strSql.AppendLine(" where SeeDocMedicId=@SeeDocMedicId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDocMedicName", SqlDbType.VarChar,50),
        //            new SqlParameter("@SeeDocMedicSalePrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SeeDocMedicNumber", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDocMedicSumPrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SeeDocMedicIsPay", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDoctorId", SqlDbType.Int,4),
        //            new SqlParameter("@SeeDocMedicId", SqlDbType.Int,4)};
        //    parameters[0].Value = model.HospitalId;
        //    parameters[1].Value = model.SeeDocMedicName;
        //    parameters[2].Value = model.SeeDocMedicSalePrice;
        //    parameters[3].Value = model.SeeDocMedicNumber;
        //    parameters[4].Value = model.SeeDocMedicSumPrice;
        //    parameters[5].Value = model.SeeDocMedicIsPay;
        //    parameters[6].Value = model.SeeDoctorId;
        //    parameters[7].Value = model.SeeDocMedicId;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// 删除一条数据
        ///// </summary>
        //public bool Delete(int SeeDocMedicId)
        //{

        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("delete from tbSeeDoctorMedicalItem ");
        //    strSql.AppendLine(" where SeeDocMedicId=@SeeDocMedicId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@SeeDocMedicId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = SeeDocMedicId;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        ///// <summary>
        ///// 批量删除数据
        ///// </summary>
        //public bool DeleteList(string SeeDocMedicIdlist )
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("delete from tbSeeDoctorMedicalItem ");
        //    strSql.AppendLine(" where SeeDocMedicId in ("+SeeDocMedicIdlist + ")  ");
        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.SeeDoctorMedicalItem GetModel(int SeeDocMedicId)
        //{

        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("select  top 1 SeeDocMedicId,HospitalId,SeeDocMedicName,SeeDocMedicSalePrice,SeeDocMedicNumber,SeeDocMedicSumPrice,SeeDocMedicIsPay,SeeDoctorId from tbSeeDoctorMedicalItem ");
        //    strSql.AppendLine(" where SeeDocMedicId=@SeeDocMedicId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@SeeDocMedicId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = SeeDocMedicId;

        //    ZX.HIS.Model.SeeDoctorMedicalItem model=new ZX.HIS.Model.SeeDoctorMedicalItem();
        //    DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
        //    if(ds.Tables[0].Rows.Count>0)
        //    {
        //        return DataRowToModel(ds.Tables[0].Rows[0]);
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.SeeDoctorMedicalItem DataRowToModel(DataRow row)
        //{
        //    ZX.HIS.Model.SeeDoctorMedicalItem model=new ZX.HIS.Model.SeeDoctorMedicalItem();
        //    if (row != null)
        //    {
        //        if(row["SeeDocMedicId"]!=null && row["SeeDocMedicId"].ToString()!="")
        //        {
        //            model.SeeDocMedicId=int.Parse(row["SeeDocMedicId"].ToString());
        //        }
        //        if(row["HospitalId"]!=null && row["HospitalId"].ToString()!="")
        //        {
        //            model.HospitalId=int.Parse(row["HospitalId"].ToString());
        //        }
        //        if(row["SeeDocMedicName"]!=null)
        //        {
        //            model.SeeDocMedicName=row["SeeDocMedicName"].ToString();
        //        }
        //        if(row["SeeDocMedicSalePrice"]!=null && row["SeeDocMedicSalePrice"].ToString()!="")
        //        {
        //            model.SeeDocMedicSalePrice=decimal.Parse(row["SeeDocMedicSalePrice"].ToString());
        //        }
        //        if(row["SeeDocMedicNumber"]!=null && row["SeeDocMedicNumber"].ToString()!="")
        //        {
        //            model.SeeDocMedicNumber=int.Parse(row["SeeDocMedicNumber"].ToString());
        //        }
        //        if(row["SeeDocMedicSumPrice"]!=null && row["SeeDocMedicSumPrice"].ToString()!="")
        //        {
        //            model.SeeDocMedicSumPrice=decimal.Parse(row["SeeDocMedicSumPrice"].ToString());
        //        }
        //        if(row["SeeDocMedicIsPay"]!=null && row["SeeDocMedicIsPay"].ToString()!="")
        //        {
        //            model.SeeDocMedicIsPay=int.Parse(row["SeeDocMedicIsPay"].ToString());
        //        }
        //        if(row["SeeDoctorId"]!=null && row["SeeDoctorId"].ToString()!="")
        //        {
        //            model.SeeDoctorId=int.Parse(row["SeeDoctorId"].ToString());
        //        }
        //    }
        //    return model;
        //}

        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public DataSet GetList(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("select SeeDocMedicId,HospitalId,SeeDocMedicName,SeeDocMedicSalePrice,SeeDocMedicNumber,SeeDocMedicSumPrice,SeeDocMedicIsPay,SeeDoctorId ");
        //    strSql.AppendLine(" FROM tbSeeDoctorMedicalItem ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.AppendLine(" where "+strWhere);
        //    }
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top,string strWhere,string filedOrder)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("select ");
        //    if(Top>0)
        //    {
        //        strSql.AppendLine(" top "+Top.ToString());
        //    }
        //    strSql.AppendLine(" SeeDocMedicId,HospitalId,SeeDocMedicName,SeeDocMedicSalePrice,SeeDocMedicNumber,SeeDocMedicSumPrice,SeeDocMedicIsPay,SeeDoctorId ");
        //    strSql.AppendLine(" FROM tbSeeDoctorMedicalItem ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.AppendLine(" where "+strWhere);
        //    }
        //    strSql.AppendLine(" order by " + filedOrder);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获取记录总数
        ///// </summary>
        //public int GetRecordCount(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("select count(1) FROM tbSeeDoctorMedicalItem ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.AppendLine(" where "+strWhere);
        //    }
        //    object obj = DbHelperSQL.GetSingle(strSql.ToString());
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.AppendLine("SELECT * FROM ( ");
        //    strSql.AppendLine(" SELECT ROW_NUMBER() OVER (");
        //    if (!string.IsNullOrEmpty(orderby.Trim()))
        //    {
        //        strSql.AppendLine("order by T." + orderby );
        //    }
        //    else
        //    {
        //        strSql.AppendLine("order by T.SeeDocMedicId desc");
        //    }
        //    strSql.AppendLine(")AS Row, T.*  from tbSeeDoctorMedicalItem T ");
        //    if (!string.IsNullOrEmpty(strWhere.Trim()))
        //    {
        //        strSql.AppendLine(" WHERE " + strWhere);
        //    }
        //    strSql.AppendLine(" ) TT");
        //    strSql.AppendLineFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///*
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@tblName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@fldName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PageSize", SqlDbType.Int),
        //            new SqlParameter("@PageIndex", SqlDbType.Int),
        //            new SqlParameter("@IsReCount", SqlDbType.Bit),
        //            new SqlParameter("@OrderType", SqlDbType.Bit),
        //            new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
        //            };
        //    parameters[0].Value = "tbSeeDoctorMedicalItem";
        //    parameters[1].Value = "SeeDocMedicId";
        //    parameters[2].Value = PageSize;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = 0;
        //    parameters[5].Value = 0;
        //    parameters[6].Value = strWhere;	
        //    return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        //}*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

